package com.xiaoxie.common.union;

import com.xiaoxie.common.enums.ReturnCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author xiaoxie
 * @create 2025-01-19
 * @Version 1.0。0
 * @Description: 统一返回结果
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class R {
    private Integer code;
    private String message;
    private Object data;

    public static R ok(Object data) {
        return new R(ReturnCode.SUCCESS.getCode(), ReturnCode.SUCCESS.getMessage(), data);
    }
    public static R ok(String message) {
        return new R(ReturnCode.SUCCESS.getCode(), message, null);
    }
    public static R ok(String message, Object data) {
        return new R(ReturnCode.SUCCESS.getCode(), message, data);
    }
    public static R ok(ReturnCode returnCode) {
        return new R(returnCode.getCode(), returnCode.getMessage(), null);
    }
    public static R ok(ReturnCode returnCode, Object data) {
        return new R(returnCode.getCode(), returnCode.getMessage(), data);
    }
    public static R ok(Integer code, String message, Object data) {
        return new R(code, message, data);
    }
    public static R fail(Object data) {
        return new R(ReturnCode.FAIL.getCode(), ReturnCode.FAIL.getMessage(), data);
    }
    public static R fail(String message) {
        return new R(ReturnCode.FAIL.getCode(), message, null);
    }
    public static R fail(String message, Object data) {
        return new R(ReturnCode.FAIL.getCode(), message, data);
    }
    public static R fail(ReturnCode returnCode) {
        return new R(returnCode.getCode(), returnCode.getMessage(), null);
    }
    public static R fail(ReturnCode returnCode, Object data) {
        return new R(returnCode.getCode(), returnCode.getMessage(), data);
    }
    public static R fail(Integer code, String message, Object data) {
        return new R(code, message, data);
    }
}
